<!-- S search -->
<app-search-bar
  [submitLoading]="tableParams.loading"
  [searchOptions]="searchOptions"
  labelFlex="50px"
  (onSearch)="queryResetData($event)"
  (onReset)="queryResetData($event)"
>
</app-search-bar>
<!-- E search -->

<nz-card class="m-t-4">
  <div class="opera-wrap">
    <button
      *ngIf="permission.userPermission.has('secondGoods:watermark:update')"
      nz-button
      nzType="primary"
      (click)="jumpPage(0)"
    >新增</button>
  </div>

  <div class="pagination-wrap-position p-t-10">
    <nz-table
      #basicTable
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      nzOuterBordered
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="tableParams.loading"
      [nzData]="tableParams.tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="tableParams.total"
      [nzPageIndex]="tableParams.page"
      [nzPageSize]="tableParams.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)"
    >
      <thead>
        <tr>
          <th nzAlign="center" nzWidth="100px">ID</th>
          <th nzAlign="center" nzWidth="120px">状态</th>
          <th nzAlign="center" nzWidth="150px">名称</th>
          <th nzAlign="center" nzWidth="150px">适用用户</th>
          <th nzAlign="center" nzWidth="120px">水印图</th>
          <th nzAlign="center" nzWidth="170px">生效时间</th>
          <th nzAlign="center" nzWidth="180px" nzRight>操作</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <!-- ID -->
          <td nzAlign="center">{{ data.id }}</td>
          <!-- 状态 -->
          <td nzAlign="center">
            <ng-container [ngSwitch]="data.status">
              <span style="color: #F56C6C;" *ngSwitchCase="0">禁用</span>
              <span style="color: #67C23A;" *ngSwitchCase="1">启用</span>
              <span *ngSwitchDefault>-</span>
            </ng-container>
          </td>
          <!-- 名称 -->
          <td nzAlign="center">{{ data.name }}</td>
          <!-- 适用用户 -->
          <td nzAlign="center">
            <ng-container [ngSwitch]="data.userType">
              <nz-tag *ngSwitchCase="0">通用</nz-tag>
              <nz-tag *ngSwitchCase="1" [nzColor]="'#87d068'">C端</nz-tag>
              <nz-tag *ngSwitchCase="2" [nzColor]="'#2db7f5'">B端</nz-tag>
              <span *ngSwitchDefault>-</span>
            </ng-container>
          </td>
          <!-- 水印图 -->
          <td nzAlign="center">
            <img
              nz-image
              width="42px"
              height="42px"
              [nzSrc]="data.img"
              [nzFallback]="fallback"
              alt=""
            />
          </td>
          <!-- 生效时间 -->
          <td nzAlign="center">
            <ng-container *ngIf="data.useBeginTime; else elseTimeTemplate">
              {{ data.useBeginTime }} ~ {{ data.useEndTime }}
            </ng-container>
            <ng-template #elseTimeTemplate>-</ng-template>
          </td>
          <!-- 操作 -->
          <td nzAlign="center" nzRight>
            <button
              nz-button
              nzType="link"
              nzSize="small"
              (click)="jumpPage(2, data)"
            >查看</button>

            <button
              *ngIf="permission.userPermission.has('secondGoods:watermark:update')"
              nz-button
              nzType="link"
              nzSize="small"
              class="m-l-8"
              (click)="jumpPage(1, data)"
            >编辑</button>
          </td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ total }} 条</ng-template>
  </div>
</nz-card>